package com.sctvcloud.renhe.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.widget.Toast;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.renhe.R;
import com.sctvcloud.renhe.base.BaseActivity;
import com.sctvcloud.renhe.beans.FProgramme;
import com.sctvcloud.renhe.beans.NewsItem;
import com.sctvcloud.renhe.ui.activities.ReviewActivity;
import com.sctvcloud.renhe.ui.utils.GlideUtil;
import com.sctvcloud.renhe.ui.utils.SkipUtil;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/13 0013.
 */

public class AnchorReDataHolder extends BaseAnchorHolder<FProgramme> implements View.OnClickListener {
    @BindView(R.id.item_anchor_recommen_data_img)
    protected CustomEXImageView img;
    @BindView(R.id.item_anchor_recommen_data_lable)
    protected CustomFontTextView lable;
    @BindView(R.id.item_anchor_recommen_data_title)
    protected CustomFontTextView title;
    @BindView(R.id.item_anchor_recommen_data_playTime)
    protected CustomFontTextView playTime;
    @BindView(R.id.item_anchor_recommen_data_intro)
    protected CustomFontTextView intro;
    @BindView(R.id.item_anchor_recommen_data_update)
    protected CustomFontTextView update;
    protected String programUrl;
    private NewsItem newsItem;
    private String showStr;

    public AnchorReDataHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FProgramme fProgramme) {
        if (!TextUtils.isEmpty(fProgramme.getProgramType())) {
            lable.setText(fProgramme.getProgramType());
//            lable.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(fProgramme.getProgramTitle())) {
            title.setText(fProgramme.getProgramTitle());
        }
        String total = fProgramme.getProgramTotal();
        String amout = fProgramme.getPlayAmount();
        if (!TextUtils.isEmpty(total) && !TextUtils.equals("0", total)) {
            showStr = "总" + total + "期";
        }
        if (!TextUtils.isEmpty(amout) && !TextUtils.equals("0", amout)) {
            showStr = "播放" + amout + "次";
        }
        if (!TextUtils.isEmpty(total) && !TextUtils.equals("0", total) && !TextUtils.isEmpty(amout) && !TextUtils.equals("0", amout)) {
            showStr = "总" + total + "期" + "|" + "播放" + amout + "次";
        }
        playTime.setText(showStr);
        if (!TextUtils.isEmpty(fProgramme.getProgramIntro())) {
            intro.setText(fProgramme.getProgramIntro());
        } else {
            intro.setText("简介:");
        }
        if (!TextUtils.isEmpty(fProgramme.getUpdateInfo())) {
            update.setText("更新至:" + fProgramme.getUpdateInfo() + "期");
        } else {
            update.setText("");
        }
        if (!TextUtils.isEmpty(fProgramme.getProgramImage())) {
            GlideUtil.getGlideWithSmall169Def(context, fProgramme.getProgramImage()).into(img);
        } else {
            img.setImageResource(R.mipmap.icon_def_16_9_s);
        }
        programUrl = fProgramme.getContentUrl();
        newsItem = fProgramme.getProgramme();
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(context, ReviewActivity.class);
        if (!TextUtils.isEmpty(programUrl) && programUrl.endsWith(".json")) {
            intent.putExtra(BaseActivity.EX_ID, programUrl);
            context.startActivity(intent);
        } else {
            Toast.makeText(context, "url错误", Toast.LENGTH_SHORT).show();
        }

    }

    @OnClick(value = {R.id.item_anchor_recommen_data_update})
    public void latestOnClick(View view) {
//        Intent intent = new Intent(context, NewesDetailActivity.class);
//        intent.putExtra(NewesDetailActivity.EX_URL, CollectionUtils.convertData(newsItem));
//        context.startActivity(intent);
        SkipUtil.skipWithNewsItem(context, newsItem,new HashMap<String, String>());
    }
}
